//
//  MRCityHotelViewController.m
//  Travel_World
//
//  Created by dllo on 15/10/19.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "MRCityHotelViewController.h"
#import "MRDestinationModel.h"
//#import "MRHotel_Model.h"
#import "MRHotel_TableViewCell.h"
#import "MRCountry_messageViewController.h"
#import "MRSearchViewController.h"

@interface MRCityHotelViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *array;

@property (nonatomic, strong) NSMutableDictionary *dic;

@property (nonatomic, strong) UIView *headerView;

@property (nonatomic, strong) UIImageView *headerImageView;

@property (nonatomic, strong) UILabel *all;

@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation MRCityHotelViewController

- (void)viewWillDisappear:(BOOL)animated
{
    UITextField *textField = (UITextField *)[self.view viewWithTag:1];
    [textField resignFirstResponder];
    
}

- (void)viewWillAppear:(BOOL)animated
{
    
    self.navigationController.navigationBar.translucent = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.title = [NSString stringWithFormat:@"%@酒店",self.content];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createTableView];
    
    [self createHeaderView];
    
    [self createData];
}

#pragma mark 数据解析
- (void)createData
{
    [QTAFNnetWorkTool getUrl:self.url body:nil hudSuperView:self.view result:QTJSON headerFile:nil success:^(id result) {
        
        self.dic = result[@"data"];
        
        self.array = [MRDestinationModel baseModelByArr:result[@"data"][@"hotel"]];
        
        [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:self.dic[@"city_photo"]]placeholderImage:[UIImage imageNamed:@"placeholder1"]];
        
        self.all.text = self.dic[@"area"][@"name"];
        self.contentLabel.text = self.dic[@"area"][@"intro"];
        
        [self.tableView reloadData];
        
    }];
    
//    NSDictionary *parameter = @{@"checkin":self.}
    
}

#pragma mark 创建头视图
- (void)createHeaderView
{
    
    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 250 * HEI)];
    self.tableView.tableHeaderView = self.headerView;
    
    self.headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 250 * HEI)];
    [self.headerView addSubview:self.headerImageView];
    
    
    // 创建一个效果,指定效果,毛玻璃
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    // 创建一个毛玻璃视图 毛玻璃
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    // 毛玻璃的透明度和颜色
    effectView.alpha = 0.5;
//    effectView.backgroundColor = [UIColor colorWithRed:1.000 green:0.913 blue:0.783 alpha:1.000];
    effectView.backgroundColor = [UIColor clearColor];
    effectView.tag = 7;
    // 让毛玻璃效果的范围和图片的尺寸相等
    effectView.frame = self.headerImageView.frame;
    [self.headerView addSubview:effectView];
    
    
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(50 * WID, 40 * HEI, 275 * WID, 30 * HEI)];
    textField.tag = 1;
    textField.layer.borderWidth = 1;
    textField.layer.borderColor = [UIColor whiteColor].CGColor;
    textField.layer.cornerRadius = 15 * HEI;
    textField.placeholder = @"搜索酒店";
    textField.delegate = self;
    [self.headerView addSubview:textField];
    
    self.all = [[UILabel alloc] initWithFrame:CGRectMake(0, 90 * HEI, WIDTH, 20 * HEI)];
    self.all.font = [UIFont systemFontOfSize:15];
    self.all.textAlignment = NSTextAlignmentCenter;
//    all.numberOfLines = 3;
    self.all.textColor = [UIColor whiteColor];
    [self.headerView addSubview:self.all];
    
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(60 * WID, 110 * HEI, 255 * WID, 70 * HEI)];
    self.contentLabel.font = [UIFont systemFontOfSize:13];
    self.contentLabel.textColor = [UIColor whiteColor];
    self.contentLabel.numberOfLines = 3;
    [self.headerView addSubview:self.contentLabel];
   
}

#pragma mark textField的协议方法,开始编辑的时候
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    MRSearchViewController *searchVC = [[MRSearchViewController alloc] init];
    
    searchVC.Id = self.Id;
    searchVC.inLabelText = self.inLabelText;
    searchVC.outLabelText = self.outLabelText;
    [self.navigationController pushViewController:searchVC animated:YES];
}

#pragma mark 创建tableView
- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.tableView.rowHeight = 100 * HEI;
}

#pragma mark tableView的cell的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;
}

#pragma mark 创建tableView的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse = @"reuse";
    MRHotel_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (self.array.count > indexPath.row) {
        if (!cell) {
            
            cell = [[MRHotel_TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
            
        }
        
        MRDestinationModel *model = self.array[indexPath.row];
        
        [cell.ImageView sd_setImageWithURL:[NSURL URLWithString:model.photo]placeholderImage:[UIImage imageNamed:@"placeholder"]];
        
        cell.title.text = model.cnname;
        cell.enTitle.text = model.enname;
        cell.star.text = model.star;
        cell.point.text = [NSString stringWithFormat:@"%@分",model.ranking.description];
        cell.local.text = model.area_name;
        
        
//        NSString *priceStr = model.price.description;
//        NSString *price = [priceStr substringWithRange:NSMakeRange(4, priceStr.length-11)];
        cell.price.text = [NSString stringWithFormat:@"%@元起",model.price.description];
        
//        cell.discount.text = model.priceoff;
        //        cell.price.text = [NSString stringWithFormat:@"%@元起",model.price];
        
        return cell;
    } else {
        
        return nil;
        
    }
}

#pragma mark tableView的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.array.count > indexPath.row) {
        
        MRCountry_messageViewController *messVC = [[MRCountry_messageViewController alloc] init];
        
        messVC.url = [NSString stringWithFormat:@"%@",[self.array[indexPath.row] Link]];
        
        [self.navigationController pushViewController:messVC animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
